<?php 

		$uid=$_SESSION['userid'];
		$res1=mysql_query(
			"SELECT
				pollid
			FROM 
				polls;"
		);
		$i=1;
		while ($result1=mysql_fetch_array($res1)) {
			$all_polls[$i] = $result1['pollid'];
			$i++;
		}
		$res2=mysql_query(
			"SELECT 	
				pollid
			FROM 
				voted
			WHERE 
				userid=".$uid.";"
		);
		$j=1;
		while ($result2=mysql_fetch_array($res2)) {
			$voted_polls[$j] = $result2['pollid'];
			$j++;
		}
		for ($ii=1 ; $ii < $i ; $ii++) {
			for ($jj=1 ; $jj < $j ; $jj++) {
				if ($all_polls[$ii]==$voted_polls[$jj]) {
					$all_polls[$ii] = NULL ;
				}
			}
		}
		$k=1;
		for ($ii=1 ; $ii < $i ; $ii++) {
			if ($all_polls[$ii]!== NULL) {		
				$no_voted[$k]=$all_polls[$ii];
				$k++;
			}
		}
		$rpoll=rand(1,$k-1);
		if ($no_voted[$rpoll]!=NULL) {
			echo "<script> window.location = \"./vote.php?id=".$no_voted[$rpoll]."\"</script>";
		}
		else {
			echo "<script> window.location = \"./browse.php?all=1\"</script>";
		}

?>